package com.hdq.controller.admin;

import com.hdq.result.PageResult;
import com.hdq.result.Result;
import com.hdq.service.ImageService;
import dto.ImageAddDTO;
import dto.ImageEditDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import vo.ImageUploadVO;

import java.util.List;

@RestController
@RequestMapping("/admin/image")
@Tag(name = "图库管理")
public class ImageController {


    @Autowired
    private ImageService imageService;
    @PostMapping("/upload")
    @Operation(summary = "图片上传")
    public List<ImageUploadVO> upload(MultipartFile[] file){
        return imageService.upload(file);
    }

    @PostMapping("/{id}")
    @Operation(summary = "新增图片")
    public Result insertPictureByCategory(@PathVariable Long id, @RequestBody List<ImageAddDTO> imageAddDTOS) {
        imageService.insertPictureByCategory(id, imageAddDTOS);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除图片")
    public Result deleteImage(@PathVariable Integer id ,@RequestBody String filename) {
        imageService.deleteImage(id,filename);
        return Result.success();
    }

    @PutMapping
    @Operation(summary = "编辑图片")
    public Result updateImage(@RequestBody ImageEditDTO imageEditDTO) {
        imageService.updateImage(imageEditDTO);
        return Result.success();
    }


    @GetMapping("/{id}")
    @Operation(summary = "查询图片")
    public Result<PageResult> getImageByCategoryByPage(@PathVariable Long id, @RequestParam Integer limit, @RequestParam Integer page) {
        PageResult list = imageService.getImageByCategory(id, limit, page);
        return Result.success(list);
    }

}
